<?php
	function getConturiInAssociativeArray($conturi) {
		$d = array();
		foreach ($conturi as $cont) {
			$d[] = array(LANG_CONT =>$cont->cont, LANG_BANCA=>$cont->banca, LANG_SUCURSALA=>$cont->sucursala);
		}
		return $d;
	}
	
	function getContacteInAssociativeArray($contacte) {
		$d = array();
		foreach ($contacte as $contact) {
			$aux = array();
			$aux[LANG_NUME_CONTACT] = $contact->nume; 
			if ($contact->sex == CT_SEX_MASCULIN)
				$aux[LANG_SEX_CONTACT] = LANG_SEX_MALE;
			else 
				$aux[LANG_SEX_CONTACT] = LANG_SEX_FEMALE;
			$aux[LANG_FUNCTIE_CONTACT] = $contact->functie; 
			$aux[LANG_TEL_FIX_CONTACT] = $contact->tel_fix; 
			$aux[LANG_TEL_FAX_CONTACT] = $contact->tel_fax; 
			$aux[LANG_TEL_MOBIL_CONTACT] = $contact->tel_mobil; 
			$d[] = $aux;
		}
		return $d;
	}
	
    require_once('paths.inc');
	require_once(INCLUDE_PATH.'constants.inc');    
    require_once('security.inc');

    require_once('page.inc');    
    require_once('utils.inc');
    require_once(DB_PATH.'db.inc');    
    
	session_start();

    check_permissions(CT_PERM_FIRME);

	ob_start();
		
	$db = db_connect();
	$indecsi = $_GET['indecsi'];
	$index_arr = explode(";", $indecsi);

	select_language();

	$id_client = $_SESSION['user_logat']->id_client;
	$firme = array();
	
	function curata($var) {
		return !($var == "");
	}
	array_filter($index_arr, "curata");


	for ($i = 0; $i < count($index_arr) - 1; $i++) {
		try {
			$firme[$i] = Firma::queryLoadById($db, $index_arr[$i], $id_client);
			
		}
		catch (QueryLoadFirmaException $e) {
			redirectOnError(CT_LOAD_FIRMA_BY_ID);
		}
	}    
    
	$firma = $firme[0];
	header("Pragma: public"); // required                                                                                                                        
    header("Expires: 0");                                                                                                                                    
	header("Content-Description: File Transfer");                                                                                                        
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");                                                                             
	header("Content-type: application/pdf");                                                                                                                 
	header('Content-Transfer-Encoding: binary');                       
	$cale_fisier = USERS_PATH . $_SESSION['user_logat']->id_user . "/firma_" . $firma->id_firma . ".pdf";                                                                                      
	header("Content-Disposition: attachment; filename=\"" . basename($cale_fisier) . '"');                  

	print_firmaWithOO($firma, $currencies);
	readfile($cale_fisier);                                             
	exit();   	
?>

